<template>
  <div class="role-dialog">
    <el-dialog :visible.sync="visible" destroy-on-close>
      <div class="panelWrap role-dialog-content">
        <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
          <div>{{ isEdit ? '修改系统角色' : '添加系统角色' }}</div>
          <i class="el-icon-close" @click="handleCloseDialog" />
        </div>

        <div class="role-content flex flexdc">
          <div class="m-b-10 m-t-20 flex role-header">
            <div class="checkbox flexdc flexcenter m-t-20">
              <div class="tree-grow m-t-10">
                <div class="flex">
                  <el-select v-model="sysName" placeholder="请选择平台" class="m-r-10" @change="handleSelectChange">
                    <el-option
                      v-for="item in sysList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                  <el-checkbox v-model="isChecked" @change="handleCheckedChange">是否可用</el-checkbox>
                </div>
                <div class="panelWrap m-t-20">
                  <div class="check-title flex fs14 cfff fwb pl p-r-20">
                    <div>基础数据菜单权限</div>
                  </div>
                  <div class="sysTree">
                    <el-tree
                      ref="tree1"
                      class="left-tree coTree"
                      :current-node-key="0"
                      :data="setTree"
                      :props="defaultProps"
                      :node-key="NODE_KEY"
                      :default-expanded-keys="[105, 1, 107, 106, 167, 177, 212, 218, 221]"
                      :show-checkbox="true"
                      :highlight-current="true"
                      :default-checked-keys="checktree"
                      @check="handleCheckChange"
                    >
                      <span slot-scope="{ node, data }" class="custom-tree-node">
                        <span>{{ node.label }}</span>
                        <el-checkbox v-model="data.displayType" class="check" @change="handleCheckTree(data)">是否可用</el-checkbox>
                      </span>
                    </el-tree>
                  </div>
                </div>
                <el-button type="primary" class="m-t-20" @click="handleTemporary">暂 存</el-button>
              </div>

            </div>
            <div class="m-l-80 m-t-40 flex flexdc">
              <div class="roleName m-t-10">
                <span class="roleName-name m-l-20"><span class="mustval">*</span>角色名称：</span>
                <el-input v-model.trim="form.name" placeholder="请输入角色名称" class="roleName-input" />
              </div>
              <div class="roleName m-t-30">
                <span class="roleName-name m-l-20"><span class="mustval">*</span>机构名称：</span>
                <el-input v-model.trim="form.orgName" readonly placeholder="请选择机构" class="roleName-input" />
                <el-button type="warning" class="iconfont icon-xuanze m-l-20" @click="handleSelect">选择机构</el-button>
              </div>
              <div class="role-find flex flexac m-t-40">
                <span class="m-l-10">角色类型：</span>
                <el-radio-group v-model="form.type" class="find-radio">
                  <el-radio label="普通角色" />
                  <el-radio label="维保人员" />
                </el-radio-group>
              </div>
              <!-- <div class="role-find flex flexac m-t-40">
                <span class="m-l-10">权限类型：</span>
                <el-radio-group v-model="form.isDataRole" class="find-radio">
                  <el-radio label="功能权限" />
                  <el-radio label="数据权限" />
                </el-radio-group>
              </div> -->
              <div class="role-find flex flexac m-t-40">
                <span class="m-l-10">角色查看数据范围：</span>
                <el-radio-group v-model="form.range" class="find-radio">
                  <el-radio label="本人" />
                  <el-radio label="本机构" />
                  <el-radio label="本机构及其下级机构" />
                </el-radio-group>
              </div>
            </div>
          </div>
          <div class="footer-btn flex flexac flextc m-t-20">
            <div>
              <el-button v-if="!isEdit" class="saveBtn btn m-r-20 el-icon-circle-check" @click="handleSave">保 存</el-button>
              <el-button v-else class="btn m-r-20 el-icon-circle-check" type="success" @click="handleEdit">更 新</el-button>
              <el-button class="btn m-t-30 el-icon-circle-close" type="warning" @click="handleCloseDialog">取 消</el-button>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>

    <SelectOrg v-model="selectVisible" @update="handleSelectUpdate" />
  </div>

</template>

<script>

import { createRoleAdd, updateRole } from '@/api/baseInfo/authority/role'
import SelectOrg from '@/components/selectOrg/index'
// import { findPlatforms } from '@/api/baseInfo/authority/resources'
import { findSysList } from '@/api/baseInfo/authority/sys'
// import { findSysList } from '@/api/baseInfo/authority/sys'
import { findMenuList } from '@/api/baseInfo/authority/menu'
import { showNotice, formatDateTime, transData } from '@/utils/toolclass'
import storage from '@/utils/storage'

export default {
  name: 'Role',
  components: { SelectOrg },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    isEdit: {
      type: Boolean,
      default: false
    },
    datarole: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      sysName: 1,
      setTrees: [],
      checktree: [],
      isChecked: false,
      checked1: false,
      checked2: false,
      checked3: false,
      checked4: false,
      checked5: false,
      checked6: false,
      checked7: false,
      checked8: false,
      checked9: false,
      checked10: false,
      isChecked1: false,
      isChecked2: false,
      isChecked3: false,
      isChecked4: false,
      isChecked5: false,
      isChecked6: false,
      isChecked7: false,
      isChecked8: false,
      isChecked9: false,
      isChecked10: false,
      sysRightList1: [],
      sysRightList2: [],
      sysRightList3: [],
      sysRightList4: [],
      sysRightList5: [],
      sysRightList6: [],
      sysRightList7: [],
      sysRightList8: [],
      sysRightList9: [],
      sysRightList10: [],
      sysList: [],
      systemList: [],
      menuRightList: [],
      selectVisible: false,
      visible: false,
      checked: false,
      disTypeList: [],
      dataList: [],
      formOrigin: {
        crtOpr: '', // 创建人ID
        dataRightList: [], // 数据权限
        isDataRole: '功能权限', // 是否数据权限（0：否；1：是）
        lstEdtOpr: '', // 最后修改人ID
        orgId: '', // 机构ID
        orgName: '', // 机构名称
        type: '普通角色',
        range: '本机构及其下级机构', // 范围（1：本人；2：本级；3：本级及下级机构；）
        id: 0, // ID
        name: '', // 角色名称
        sysRightList: [], // 平台功能权限
        displayType: 1, // 显示类型（1：可用且可显示；2：可显示但不可用；）
        menuRightList: [], // 菜单功能权限
        buttonRightList: [
          {
            buttonId: 9999,
            buttonName: '',
            displayType: 1,
            menuId: ''
          }
        ], // 按钮功能权限
        buttonId: '', // 按钮ID
        buttonName: '', // 按钮名
        menuId: '', // 菜单ID
        menuName: '', // 菜单名
        parentId: '', // 父级ID（查询)
        sort: '', // 排序号
        url: '', // URL
        sysId: '', // 系统ID
        sysName: '', // 系统名
        version: 1 // 版本号
      },
      form: { ...this.datarole },
      setTree1: [], // tree数据
      NODE_KEY: 'id', // id对应字段
      defaultProps: {// 默认设置
        children: 'children',
        label: 'name'
      },
      param: {
        id: '',
        name: '',
        pageIndex: 1,
        pageSize: 100
      },
      menu1: [],
      menu2: [],
      menu3: [],
      menu4: [],
      menu5: [],
      menu6: [],
      menu7: [],
      menu8: [],
      menu9: [],
      menu10: []
    }
  },
  computed: {
    setTree() {
      return this.setTrees
    }
  },
  watch: {
    visible(v) {
      this.$emit('input', v)
    },
    value(v) {
      this.visible = v
    },
    datarole(v) {
      if (v.id === 0) {
        this.form = { ...this.formOrigin }
      } else {
        // console.log(v)
        this.form = { ...v }
        // 平台回显 --- 平台是否可用回显
        v.sysRightList.map(item => {
          if (this.sysName === 1 && item.sysId === 1) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 105) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems1.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems1.splice(i, 1)
                }
              })
            })
            const newArr1 = [...item.menuRightList, ...this.sysTems1]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 1).then(res => {
              if (res.code === '000000') {
                const newArr11 = newArr1.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                // console.log(newArr11)
                // console.log(this.sysTems1)
                this.setTrees = transData(newArr11, 'id', 'parentId')
              }
            })
            // console.log(this.setTrees)
          }
          if (this.sysName === 2 && item.sysId === 2) {
            // console.log(item.sysId)
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 1) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems2.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems2.splice(i, 1)
                }
              })
            })
            const newArr2 = [...item.menuRightList, ...this.sysTems2]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 2).then(res => {
              if (res.code === '000000') {
                // console.log(item.menuRightList)
                // console.log(res.data)
                const newArr22 = newArr2.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                // console.log(this.sysTems2)
                this.setTrees = transData(newArr22, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 3 && item.sysId === 3) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 107) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems3.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems3.splice(i, 1)
                }
              })
            })
            const newArr3 = [...item.menuRightList, ...this.sysTems3]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 3).then(res => {
              if (res.code === '000000') {
                const newArr33 = newArr3.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr33, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 4 && item.sysId === 4) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 106) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems4.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems4.splice(i, 1)
                }
              })
            })
            const newArr4 = [...item.menuRightList, ...this.sysTems4]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 4).then(res => {
              if (res.code === '000000') {
                const newArr44 = newArr4.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                // console.log(newArr44)
                this.setTrees = transData(newArr44, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 5 && item.sysId === 5) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 167) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems5.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems5.splice(i, 1)
                }
              })
            })
            const newArr5 = [...item.menuRightList, ...this.sysTems5]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 5).then(res => {
              if (res.code === '000000') {
                const newArr55 = newArr5.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr55, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 6 && item.sysId === 6) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 177) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems6.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems6.splice(i, 1)
                }
              })
            })
            const newArr6 = [...item.menuRightList, ...this.sysTems6]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 6).then(res => {
              if (res.code === '000000') {
                const newArr66 = newArr6.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr66, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 7 && item.sysId === 7) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 212) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems7.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems7.splice(i, 1)
                }
              })
            })
            const newArr7 = [...item.menuRightList, ...this.sysTems7]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 7).then(res => {
              if (res.code === '000000') {
                const newArr77 = newArr7.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr77, 'id', 'parentId')
              }
            })
          }
          if (this.sysName === 8 && item.sysId === 8) {
            // console.log(item)
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.sysTems8.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.sysTems8.splice(i, 1)
                }
              })
            })
            const newArr8 = [...item.menuRightList, ...this.sysTems8]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 8).then(res => {
              if (res.code === '000000') {
                const newArr88 = newArr8.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr88, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
          }
          if (this.sysName === 9 && item.sysId === 9) {
            // this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            this.setTrees = transData(this.sysTems9, 'id', 'parentId')
          }
          if (this.sysName === 10 && item.sysId === 10) {
            // this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            this.setTrees = transData(this.sysTems10, 'id', 'parentId')
          }
        })
      }
    }
  },
  created() {
    this.userInfo = JSON.parse(storage.get('userInfo'))
    this.getSystemList()
    this.handleGetSysMenu()
  },
  methods: {
    handleTemporary() {
      if (this.$refs.tree1 !== undefined) {
        const menu = this.$refs.tree1.getCheckedNodes().concat(this.$refs.tree1.getHalfCheckedNodes())
        // console.log(menu)
        // console.log(this.sysName)
        if (this.sysName === 1) {
          this.menux1 = menu.map(item => {
            if (item.sysId === 1) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system1 = this.sysList.filter(item => { if (item.id === 1) return item })
          this.sysRightList1 = [{
            displayType: this.isChecked1 === true ? 1 : 2,
            menuRightList: this.menux1,
            sysId: system1[0].id,
            sysName: system1[0].name
          }]
          // console.log(this.sysRightList1)
          return this.sysRightList1
        }
        if (this.sysName === 2) {
          this.menux2 = menu.map(item => {
            if (item.sysId === 2) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system2 = this.sysList.filter(item => { if (item.id === 2) return item })
          this.sysRightList2 = [{
            displayType: this.isChecked2 === true ? 1 : 2,
            menuRightList: this.menux2,
            sysId: system2[0].id,
            sysName: system2[0].name
          }]
          // console.log(this.sysRightList2)
          return this.sysRightList2
        }
        if (this.sysName === 3) {
          this.menux3 = menu.map(item => {
            if (item.sysId === 3) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system3 = this.sysList.filter(item => { if (item.id === 3) return item })
          this.sysRightList3 = [{
            displayType: this.isChecked3 === true ? 1 : 2,
            menuRightList: this.menux3,
            sysId: system3[0].id,
            sysName: system3[0].name
          }]
          // console.log(this.sysRightList3)
          return this.sysRightList3
        }
        if (this.sysName === 4) {
          this.menux4 = menu.map(item => {
            if (item.sysId === 4) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system4 = this.sysList.filter(item => { if (item.id === 4) return item })
          this.sysRightList4 = [{
            displayType: this.isChecked4 === true ? 1 : 2,
            menuRightList: this.menux4,
            sysId: system4[0].id,
            sysName: system4[0].name
          }]
          return this.sysRightList4
        }
        if (this.sysName === 5) {
          this.menux5 = menu.map(item => {
            if (item.sysId === 5) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system5 = this.sysList.filter(item => { if (item.id === 5) return item })
          this.sysRightList5 = [{
            displayType: this.isChecked5 === true ? 1 : 2,
            menuRightList: this.menux5,
            sysId: system5[0].id,
            sysName: system5[0].name
          }]
          return this.sysRightList5
        }
        if (this.sysName === 6) {
          this.menux6 = menu.map(item => {
            if (item.sysId === 6) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system6 = this.sysList.filter(item => { if (item.id === 6) return item })
          this.sysRightList6 = [{
            displayType: this.isChecked6 === true ? 1 : 2,
            menuRightList: this.menux6,
            sysId: system6[0].id,
            sysName: system6[0].name
          }]
          return this.sysRightList6
        }
        if (this.sysName === 7) {
          this.menux7 = menu.map(item => {
            if (item.sysId === 7) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system7 = this.sysList.filter(item => { if (item.id === 7) return item })
          this.sysRightList7 = [{
            displayType: this.isChecked7 === true ? 1 : 2,
            menuRightList: this.menux7,
            sysId: system7[0].id,
            sysName: system7[0].name
          }]
          return this.sysRightList7
        }
        if (this.sysName === 8) {
          this.menux8 = menu.map(item => {
            if (item.sysId === 8) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system8 = this.sysList.filter(item => { if (item.id === 8) return item })
          this.sysRightList8 = [{
            displayType: this.isChecked8 === true ? 1 : 2,
            menuRightList: this.menux8,
            sysId: system8[0].id,
            sysName: system8[0].name
          }]
          return this.sysRightList8
        }
        if (this.sysName === 9) {
          this.menux9 = menu.map(item => {
            if (item.sysId === 9) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system9 = this.sysList.filter(item => { if (item.id === 9) return item })
          this.sysRightList9 = [{
            displayType: this.isChecked9 === true ? 1 : 2,
            menuRightList: this.menux9,
            sysId: system9[0].id,
            sysName: system9[0].name
          }]
          return this.sysRightList9
        }
        if (this.sysName === 10) {
          // console.log(this.sysName)
          this.menux10 = menu.map(item => {
            if (item.sysId === 10) {
              const items = {
                displayType: item.displayType === true ? 1 : 2,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            }
          })
          const system10 = this.sysList.filter(item => { if (item.id === 10) return item })
          this.sysRightList10 = [{
            displayType: this.isChecked10 === true ? 1 : 2,
            menuRightList: this.menux10,
            sysId: system10[0].id,
            sysName: system10[0].name
          }]
          // console.log(this.sysRightList10)
          return this.sysRightList10
        }
      }
    },
    handleCheckChange(v) {
      if (this.$refs.tree1 !== undefined) {
        // const menu1 = this.$refs.tree1.getCheckedNodes().concat(this.$refs.tree1.getHalfCheckedNodes())
        // console.log(menu1)
      }
    },
    handleCheckedChange(v) {
      if (this.sysName === 1) {
        // console.log(v)
        // console.log(this.sysName)
        findMenuList('', '', 1, 100000, 1).then(res => {
          if (res.code === '000000') {
            const newMenu1 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu1, 'id', 'parentId')
            this.isChecked1 = v
            return this.isChecked1
          }
        })
      }
      if (this.sysName === 2) {
        findMenuList('', '', 1, 100000, 2).then(res => {
          if (res.code === '000000') {
            const newMenu2 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu2, 'id', 'parentId')
            this.isChecked2 = v
            return this.isChecked2
          }
        })
      }
      if (this.sysName === 3) {
        findMenuList('', '', 1, 100000, 3).then(res => {
          if (res.code === '000000') {
            const newMenu3 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu3, 'id', 'parentId')
            this.isChecked3 = v
            return this.isChecked3
          }
        })
      }
      if (this.sysName === 4) {
        findMenuList('', '', 1, 100000, 4).then(res => {
          if (res.code === '000000') {
            // console.log('sysList1', res.data)
            const newMenu4 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu4, 'id', 'parentId')
            this.isChecked4 = v
            return this.isChecked4
          }
        })
      }
      if (this.sysName === 5) {
        findMenuList('', '', 1, 100000, 5).then(res => {
          if (res.code === '000000') {
            const newMenu5 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu5, 'id', 'parentId')
            this.isChecked5 = v
            return this.isChecked5
          }
        })
      }
      if (this.sysName === 6) {
        findMenuList('', '', 1, 100000, 6).then(res => {
          if (res.code === '000000') {
            const newMenu6 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu6, 'id', 'parentId')
            this.isChecked6 = v
            return this.isChecked6
          }
        })
      }
      if (this.sysName === 7) {
        findMenuList('', '', 1, 100000, 7).then(res => {
          if (res.code === '000000') {
            const newMenu7 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu7, 'id', 'parentId')
            this.isChecked7 = v
            return this.isChecked7
          }
        })
      }
      if (this.sysName === 8) {
        findMenuList('', '', 1, 100000, 8).then(res => {
          if (res.code === '000000') {
            const newMenu8 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu8, 'id', 'parentId')
            this.isChecked8 = v
            return this.isChecked8
          }
        })
      }
      if (this.sysName === 9) {
        findMenuList('', '', 1, 100000, 9).then(res => {
          if (res.code === '000000') {
            const newMenu9 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu9, 'id', 'parentId')
            this.isChecked9 = v
            return this.isChecked9
          }
        })
      }
      if (this.sysName === 10) {
        findMenuList('', '', 1, 100000, 10).then(res => {
          if (res.code === '000000') {
            const newMenu10 = res.data.map(item => {
              const items = {
                displayType: v,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            // console.log(this.sysMenu)
            this.setTrees = transData(newMenu10, 'id', 'parentId')
            this.isChecked10 = v
            return this.isChecked10
          }
        })
      }
    },
    handleSelectChange(v) {
      // console.log(v)

      this.handleGetSysMenu(v)
      if (this.isEdit === false) {
        if (v === 1) {
          this.isChecked === this.isChecked1
          return
        } else {
          this.isChecked = false
        }
        if (v === 2) {
          this.isChecked === this.isChecked2
          return
        } else {
          this.isChecked = false
        }
        if (v === 3) {
          this.isChecked === this.isChecked3
          return
        } else {
          this.isChecked = false
        }
        if (v === 4) {
          this.isChecked === this.isChecked4
          return
        } else {
          this.isChecked = false
        }
        if (v === 5) {
          this.isChecked === this.isChecked5
          return
        } else {
          this.isChecked = false
        }
        if (v === 6) {
          this.isChecked === this.isChecked6
          return
        } else {
          this.isChecked = false
        }
        if (v === 7) {
          this.isChecked === this.isChecked7
          return
        } else {
          this.isChecked = false
        }
        if (v === 8) {
          this.isChecked === this.isChecked8
          return
        } else {
          this.isChecked = false
        }
        if (v === 9) {
          this.isChecked === this.isChecked9
          return
        } else {
          this.isChecked = false
        }
        if (v === 10) {
          this.isChecked === this.isChecked10
          return
        } else {
          this.isChecked = false
        }
      }
      // else {
      //   // console.log(this.form.sysRightList)
      //   this.form.sysRightList.map(item => {
      //     if (item.sysId === 1) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 2) {
      //       // console.log(this.setTrees)
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 3) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 4) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 5) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 6) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 7) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 8) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //     if (item.sysId === 9) {
      //       this.isChecked === item.displayType === 1
      //       return
      //     } else {
      //       this.isChecked = false
      //     }
      //   })
      // }
    },
    handleCheckTree(data) {
      //
    },
    // 添加
    handleSave() {
      // console.log(this.form.sysRightList)
      this.form.sysRightList = [...this.sysRightList1, ...this.sysRightList2, ...this.sysRightList3, ...this.sysRightList4, ...this.sysRightList5, ...this.sysRightList6, ...this.sysRightList7, ...this.sysRightList8, ...this.sysRightList9, ...this.sysRightList10]
      if (!(/^\S+$/.test(this.form.name))) {
        showNotice('error', '提示', '请输入角色名称')
        return
      }
      if (!(/^\S+$/.test(this.form.orgName))) {
        showNotice('error', '提示', '请选择机构')
        return
      }

      const params = {
        crtOpr: this.form.crtOpr === '' ? this.userInfo.userId : this.form.crtOpr,
        dataRightList: [
          {
            orgId: this.form.orgId,
            orgName: this.form.orgName,
            range: this.form.range === '本人' ? 1 : this.form.range === '本机构' ? 2 : 3
          }
        ],
        id: this.form.id,
        isDataRole: this.form.isDataRole === '功能权限' ? 0 : 1,
        lstEdtOpr: this.isEdit === false ? null : this.form.lstEdtOpr === null ? this.userInfo.userId : this.form.lstEdtOpr,
        name: this.form.name,
        type: this.form.type === '普通角色' ? 1 : 2,
        sysRightList: this.form.sysRightList,
        version: this.form.version ? this.form.version : 1
      }
      // console.log(this.form.sysRightList)
      // console.log(params)
      this.handleCreateAdd(params)
    },
    handleCreateAdd(data) {
      createRoleAdd(data).then(res => {
        if (res.code === '000000') {
          showNotice('success', '提示', '添加成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        } else {
          if (res.msg === '失败') {
            showNotice('error', '提示', '添加失败')
          } else {
            showNotice('error', '提示', res.msg)
          }
        }
      })
    },
    unique(arr) {
      return [...new Set(arr.map(e => JSON.stringify(e)))].map(e => JSON.parse(e))
    },
    // 编辑
    handleEdit() {
      // console.log(this.form)
      // console.log(this.form.sysRightList)
      const sysRightList = [...this.sysRightList1, ...this.sysRightList2, ...this.sysRightList3, ...this.sysRightList4, ...this.sysRightList5, ...this.sysRightList6, ...this.sysRightList7, ...this.sysRightList8, ...this.sysRightList9, ...this.sysRightList10]
      // this.form.sysRightList = [...this.form.sysRightList, ...sysRightList]
      // console.log(sysRightList)
      sysRightList.map(item => {
        this.form.sysRightList.map((item1, i) => {
          if (item.sysId === item1.sysId) {
            this.form.sysRightList.splice(i, 1)
            this.form.sysRightList = [...this.form.sysRightList, ...sysRightList]
          } else {
            this.form.sysRightList = [...this.form.sysRightList, ...sysRightList]
          }
        })
      })
      this.form.sysRightList = this.unique(this.form.sysRightList)
      // console.log(sysRightList)
      if (!(/^\S+$/.test(this.form.name))) {
        showNotice('error', '提示', '请输入角色名称')
        return
      }
      if (!(/^\S+$/.test(this.form.orgName))) {
        showNotice('error', '提示', '请选择机构')
        return
      }

      const params = {
        crtOpr: this.form.crtOpr === '' ? this.userInfo.userId : this.form.crtOpr,
        dataRightList: [
          {
            orgId: this.form.orgId,
            orgName: this.form.orgName,
            range: this.form.range === '本人' ? 1 : this.form.range === '本机构' ? 2 : 3
          }
        ],
        id: this.form.id,
        isDataRole: this.form.isDataRole === '功能权限' ? 0 : 1,
        lstEdtOpr: this.isEdit === false ? null : this.form.lstEdtOpr === null ? this.userInfo.userId : this.form.lstEdtOpr,
        name: this.form.name,
        type: this.form.type === '普通角色' ? 1 : 2,
        sysRightList: this.form.sysRightList,
        version: this.form.version ? this.form.version : 1
      }
      // console.log(params)
      this.handleUpdates(params)
    },
    handleUpdates(data) {
      updateRole(data).then(res => {
        if (res.code === '000000') {
          showNotice('success', '提示', '修改成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        } else {
          if (res.msg === '失败') {
            showNotice('error', '提示', '修改失败')
          } else {
            showNotice('error', '提示', res.msg)
          }
        }
      })
    },
    // 查询所有机构弹窗
    handleSelect() {
      this.selectVisible = true
    },
    // 机构信息更新回调
    handleSelectUpdate(row) {
      // console.log(row)
      this.form.orgName = row.name
      this.form.orgId = row.id
    },
    sortData(list) {
      for (var i = 1; i < list.length; i++) {
        for (var j = 0; j < list.length - 1; j++) {
          if (list[j].id > list[j + 1].id) {
            var temp = list[j]
            list[j] = list[j + 1]
            list[j + 1] = temp
          }
        }
      }
      // console.log(list)// 此时lists就是按照积分高低排序之后的列表
      return list
    },
    // 获取平台列表
    getSystemList() {
      findSysList('', '', 1, 100).then(res => {
      // findSysList('', '', 1, 10).then(res => {
        if (res.code === '000000') {
          // console.log(res)
          // this.displayTypes = res.data.map(item => item.id)
          // this.systemList = res.data.map(item => item.id)
          this.sysList = this.sortData(res.data)
        }
        // console.log(this.sysList)
      })
    },
    // 获取公司能够使用的系统下的所有权限
    handleGetSysMenu(v) {
      // console.log(v)
      if (this.isEdit === true) {
        this.form.sysRightList.map(item => {
          if (v === 1 && item.sysId === 1) {
            // console.log(this.data1)
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 105) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data1.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data1.splice(i, 1)
                }
              })
            })
            const newArr1 = [...item.menuRightList, ...this.data1]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 1).then(res => {
              if (res.code === '000000') {
                const newArr11 = newArr1.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr11, 'id', 'parentId')
              }
            })
            // console.log(this.setTrees)
          } else {
            this.isChecked = false
          }
          if (v === 2 && item.sysId === 2) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 1) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              // console.log(this.data2)
              this.data2.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data2.splice(i, 1)
                }
              })
            })
            const newArr2 = [...item.menuRightList, ...this.data2]
            // console.log(newArr4)
            findMenuList('', '', 1, 100000, 2).then(res => {
              if (res.code === '000000') {
                const newArr22 = newArr2.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                // console.log(this.sysTems2)
                this.setTrees = transData(newArr22, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
          } else {
            this.isChecked = false
          }
          if (v === 3 && item.sysId === 3) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 107) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data3.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data3.splice(i, 1)
                }
              })
            })
            const newArr3 = [...item.menuRightList, ...this.data3]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 3).then(res => {
              if (res.code === '000000') {
                const newArr33 = newArr3.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr33, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
          } else {
            this.isChecked = false
          }
          if (v === 4 && item.sysId === 4) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 106) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data4.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data4.splice(i, 1)
                }
              })
            })
            const newArr4 = [...item.menuRightList, ...this.data4]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 4).then(res => {
              if (res.code === '000000') {
                const newArr44 = newArr4.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr44, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
            return
          } else {
            this.isChecked = false
          }
          if (v === 5 && item.sysId === 5) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 167) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data5.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data5.splice(i, 1)
                }
              })
            })
            const newArr5 = [...item.menuRightList, ...this.data5]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 5).then(res => {
              if (res.code === '000000') {
                const newArr55 = newArr5.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr55, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
            return
          } else {
            this.isChecked = false
          }
          if (v === 6 && item.sysId === 6) {
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 177) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data6.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data6.splice(i, 1)
                }
              })
            })
            const newArr6 = [...item.menuRightList, ...this.data6]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 6).then(res => {
              if (res.code === '000000') {
                const newArr66 = newArr6.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr66, 'id', 'parentId')
              }
            })
          } else {
            this.isChecked = false
          }
          if (v === 7 && item.sysId === 7) {
            this.checktree = []
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 212) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data7.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data7.splice(i, 1)
                }
              })
            })
            const newArr7 = [...item.menuRightList, ...this.data7]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 7).then(res => {
              if (res.code === '000000') {
                const newArr77 = newArr7.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr77, 'id', 'parentId')
              }
            })
          } else {
            this.isChecked = false
          }
          if (v === 8 && item.sysId === 8) {
            // console.log(item)
            this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
            item.menuRightList.map(item1 => {
              this.data8.filter((item2, i) => {
                if (item1.menuId === item2.id) {
                  return this.data8.splice(i, 1)
                }
              })
            })
            const newArr8 = [...item.menuRightList, ...this.data8]
            // console.log(newArr1)
            // console.log(this.sysMenu)
            findMenuList('', '', 1, 100000, 8).then(res => {
              if (res.code === '000000') {
                const newArr88 = newArr8.map(item => {
                  const items = {
                    displayType: item.displayType === 1,
                    id: item.id || item.menuId,
                    name: item.name || item.menuName,
                    parentId: item.parentId,
                    sort: item.sort,
                    sysId: item.sysId,
                    sysName: item.sysName || res.data[0].sysName,
                    url: item.url,
                    version: item.version || res.data[0].version
                  }
                  return items
                })
                this.setTrees = transData(newArr88, 'id', 'parentId')
              }
            })
            // console.log(this.checktree)
          } else {
            this.isChecked = false
          }
          if (v === 9 && item.sysId === 9) {
            // this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
          } else {
            this.isChecked = false
          }
          if (v === 10 && item.sysId === 10) {
            // this.checktree = item.menuRightList.length <= 0 ? [] : item.menuRightList.map(item => { if (item.menuId !== 218 && item.menuId !== 221) { return item.menuId } })
            this.isChecked = item.displayType === 1
            this.sysName = item.sysId
          } else {
            this.isChecked = false
          }
        })
        this.setTrees.map(item => {
          if (item.sysId !== v) {
            if (v === 1) { this.setTrees = transData(this.data1, 'id', 'parentId') }
            if (v === 2) { this.setTrees = transData(this.data2, 'id', 'parentId') }
            if (v === 3) { this.setTrees = transData(this.data3, 'id', 'parentId') }
            if (v === 4) { this.setTrees = transData(this.data4, 'id', 'parentId') }
            if (v === 5) { this.setTrees = transData(this.data5, 'id', 'parentId') }
            if (v === 6) { this.setTrees = transData(this.data6, 'id', 'parentId') }
            if (v === 7) { this.setTrees = transData(this.data7, 'id', 'parentId') }
            if (v === 8) { this.setTrees = transData(this.data8, 'id', 'parentId') }
            if (v === 9) { this.setTrees = transData(this.data9, 'id', 'parentId') }
            if (v === 10) { this.setTrees = transData(this.data10, 'id', 'parentId') }
          }
        })
        for (var i = 0; i < this.form.sysRightList.length; i++) {
          if (v === this.form.sysRightList[i].sysId) {
            // console.log(this.form.sysRightList[i])
            this.isChecked = this.form.sysRightList[i].displayType === 1
            this.sysName = this.form.sysRightList[i].sysId
          }
        }
      }
      const id = v || 1
      // console.log(id)
      findMenuList(this.param.id, this.param.name, this.param.pageIndex, this.param.pageSize, id).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.sysMenu = res.data
          if (this.isEdit === false) {
            this.setTree11 = res.data.map(item => {
              const items = {
                displayType: item.displayType === null ? 1 : item.displayType,
                id: item.id,
                name: item.name,
                parentId: item.parentId,
                sort: item.sort,
                sysId: item.sysId,
                sysName: item.sysName,
                url: item.url,
                version: item.version
              }
              return items
            })
            this.setTrees = transData(res.data, 'id', 'parentId')
          }
        }
      })
      findMenuList('', '', 1, 100000, 1).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data1 = res.data
          this.sysTems1 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 2).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data2 = res.data
          this.sysTems2 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 3).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data3 = res.data
          this.sysTems3 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 4).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data4 = res.data
          this.sysTems4 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 5).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data5 = res.data
          this.sysTems5 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 6).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data6 = res.data
          this.sysTems6 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 7).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data7 = res.data
          this.sysTems7 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 8).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data8 = res.data
          this.sysTems8 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 9).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data9 = res.data
          this.sysTems9 = res.data
        }
      })
      findMenuList('', '', 1, 100000, 10).then(res => {
        if (res.code === '000000') {
          // console.log('sysList1', res.data)
          this.data10 = res.data
          this.sysTems10 = res.data
        }
      })
    },
    handleCloseDialog() {
      this.$emit('handleCloseDialog')
    },

    handleExportExcel() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('@/excel/Export2Excel')
        const tHeader = ['系统ID', '资源图标', '父资源', '资源ID', '资源名称', '资源顺序', '资源类型', '资源链接']
        const filterVal = ['sysId', 'iconUrl', 'parentId', 'resourceId', 'orgName', 'resourceSort', 'resourceType', 'resourceUrl']
        const data = this.formatJson(filterVal, this.dataList)
        export_json_to_excel(tHeader, data, '系统平台权限资源表(' + formatDateTime().ymd) + ')'
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    }
  }
}
</script>

<style lang="scss">
@import "@/styles/public.scss";
.role-dialog {
  .role-dialog-content {
    width: 1000px;
    height: 700px;
    // margin: 0 0 0 -200px;
    background: #ffffff;
    .role-content {
      .role-header {
        height: 500px;
        .checkbox {
          width: 500px;
          // min-height: 660px;
          .checkgou {
            // position: absolute;
            // top: 0;
            // right: 10px;
            .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
              background-color: #3cb371;
              border-color: #3cb371;
            }
            .el-checkbox__input.is-checked+.el-checkbox__label {
              color: #3cb371;
            }
          }

          .custom-tree-node {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 14px;
            padding-right: 8px;
            .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
              background-color: #3cb371;
              border-color: #3cb371;
            }
            .el-checkbox__input.is-checked+.el-checkbox__label {
              color: #3cb371;
            }
          }
          .tree-grow {
            max-width: 260px;
            // height: 200px;
            // margin-left: -24px;
            // margin-left: -124px;
            .check-title {
              line-height: 34px;
              background: #3cb371;
              font-size: 12px;
            }
            .sysTree {
              height: 260px;
              overflow: auto;
              .coTree {
                // overflow: auto;
                height: 160px;
                .el-tree-node .el-checkbox .el-checkbox__inner {
                  display: block !important;
                }
              }
            }
          }
        }
        .roleName {
          margin-left: -130px;
        }
        .role-find {
          margin-left: -114px;
        }
      }
      .footer-btn {
        // height: 180px;
      }
    }
  }
}
</style>
